package com.example.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.project.entity.Category;
import com.example.project.mapper.CategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 图书分类Controller
 *
 * @author changyao
 * @date 2024-12-04
 */
@RestController
@RequestMapping("/project/category")
public class CategoryController
{
    @Autowired
    private CategoryMapper categoryMapper;

    /**
     * 查询图书分类列表
     */
    @GetMapping("/list")
    public List<Category> list()
    {
        QueryWrapper<Category> queryWrapper=new QueryWrapper<>();
        return categoryMapper.selectList(queryWrapper);
    }




    /**
     * 获取图书分类详细信息
     */
    @PostMapping("/detil")
    public Category getInfo(@RequestBody Category category)
    {
        return categoryMapper.selectById(category);
    }


    /**
     * 新增图书分类
     */
    @PostMapping("/add")
    public int add(@RequestBody Category category)
    {
        return categoryMapper.insert(category);
    }

    /**
     * 修改图书分类
     */
    @PostMapping("/edit")
    public int edit(@RequestBody Category category)
    {
        return categoryMapper.updateById(category);
    }

    /**
     * 删除图书分类
     */
	@PostMapping("/del")
    public int remove(@RequestBody Category category)
    {
        return categoryMapper.deleteById(category);
    }
}
